<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mslides extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function getSlides()
    {
        $sql = "SELECT slides FROM slides LIMIT 1";
        $data = $this->db->query($sql)->row_array();
        return $data;
    }
    
    public function updateSlides($arr)
    {
        $data = array(
            'slides' => json_encode($arr)
        );
		
        $this->db->update('slides', $data, "id = 1");
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return $data;
    }
	
	public function listCoupon(){
		return $this->db->query('SELECT * FROM ecoupon WHERE active = 1')->result_array();
	}
	
	public function listIncentive(){
		return $this->db->query('SELECT * FROM incentive_restaurant WHERE active = 1')->result_array();
	}
	
	public function ajaxgetlistcoupon($ids){
		//$arr, $id = 0, $name, $option,$ids
		$arr = $this->db->query('SELECT * FROM ecoupon WHERE active = 1')->result_array();
		$id = 0; 
		$name = 'coupon_id';
		$option = 'Chọn coupon';
		$html = '<select  name="'.$name.$ids.'" id="'.$name.'">';
        if(in_array($option, array(null, '', '0', 0))){
            $html .= '<option value="">'.$option.'</option>';
        }
        foreach($arr AS $el=>$le)
        {
            if($le['id'] == $id)
            {
                $selected = 'selected="selected"';
            }else{
                $selected = '';
            }
            $html .= '<option value="'.$le['id'].'" '.$selected.'>'.$le['title'].'</option>';
        }
        $html .= '</select>';
        return $html;
	}
}